package com.litchishell;

import java.awt.*;

/**
 * @author LitchiShell
 * @description:
 * @create 2022-02-02
 */
public class Background {

    /* 总分 */
    static int SUM = 0;

    /* 药水总数 */
    static int POTION_NUM = 3;

    /* 药水是否生效中 */
    static boolean OPTION_FLAG = false;

    /* 关卡数 */
    static int LEVEL = 1;

    /* 目标分数 */
    int goal = LEVEL * 5;

    /* 开始时间 */
    long startTime;

    /* 结束时间 */
    long endTime;

    /* 药水价格 */
    int option_price = (int) (Math.random() * 10);

    /* 是否进入商店 false 不购买 */
    boolean shop = false;

    /* 游戏背景 */
    Image bg = Toolkit.getDefaultToolkit().getImage("imgs/bg.jpg");

    /* 天空背景 */
    Image sky = Toolkit.getDefaultToolkit().getImage("imgs/bg1.jpg");

    /* 矿工 */
    Image miner = Toolkit.getDefaultToolkit().getImage("imgs/peo.png");

    /* 药水 */
    Image potion = Toolkit.getDefaultToolkit().getImage("imgs/water.png");



    void printSelf(Graphics g) {
        g.drawImage(sky, 0, 0, null);
        g.drawImage(bg, 0, 200, null);

        switch(GameWin.GAME_STATE) {
            case 0 :
                drawWords(g, 80, Color.GREEN, "准备开始", 200, 400);
                break;
            case 1 :
                g.drawImage(miner, 310, 50, null);
                drawWords(g, 30, Color.BLACK, "积分:"+SUM, 30, 150);

                g.drawImage(potion, 450, 40, null);
                drawWords(g, 30, Color.BLACK, "*"+POTION_NUM, 510, 70);

                drawWords(g, 30, Color.BLACK, "第"+LEVEL+"关", 30, 60);

                drawWords(g, 30, Color.BLACK, "目标:"+goal, 30, 110);

                endTime = System.currentTimeMillis();
                long time = 20 - (endTime - startTime) / 1000;
                drawWords(g, 30, Color.BLACK, "时间:"+(time > 0 ? time : 0), 520, 150);
                break;
            case 2 :
                g.drawImage(potion, 300, 400, null);
                drawWords(g, 30, Color.BLACK, "药水价格:"+option_price, 300, 500);
                drawWords(g, 30, Color.BLACK, "是否购买？", 510, 550);
                if (shop) {
                    SUM  = SUM - option_price;
                    POTION_NUM++;
                    shop = false;
                    GameWin.GAME_STATE = 1;
                    startTime = System.currentTimeMillis();
                }
                break;
            case 3 :
                drawWords(g, 80, Color.BLACK, "失败", 250, 350);
                drawWords(g, 80, Color.BLACK, "积分:"+SUM, 200, 450);
                break;
            case 4 :
                drawWords(g, 80, Color.RED, "成功", 250, 350);
                drawWords(g, 80, Color.BLACK, "积分:"+SUM, 200, 450);
                break;
            default:
        }

    }

    /* true 倒计时完成、false正在倒计时 */
    boolean gameTime() {
        long time = (endTime - startTime) / 1000;
        return time > 20 ? true : false;
    }

    public static void drawWords(Graphics g, int size, Color color, String str, int x, int y){
        g.setColor(color);
        g.setFont(new Font("仿宋", Font.BOLD, size));
        g.drawString(str, x, y);
    }

    void reGame() {
        /* 总分 */
        int sum = 0;

        /* 药水总数 */
        int potion_num = 3;

        /* 药水是否生效中 */
        boolean option_flag = false;

        /* 关卡数 */
        int level = 1;

        /* 目标分数 */
        int goal = level * 5;
    }
}
